//
//  HomeDetialHeaderVIew.m
//  Arts1
//
//  Created by Mac Jc on 15/10/4.
//  Copyright © 2015年 Arts1. All rights reserved.
//

#import "HomeDetialHeaderVIew.h"
#import "AllHeader.h"


@implementation HomeDetialHeaderVIew

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = kCustomColor(235, 235, 235, 1);
        
//        _backgroundShadowView = [[UIView alloc] initWithFrame:self.bounds];
//        _backgroundShadowView.backgroundColor = [UIColor whiteColor];
//        [UIView viewWideForShadowColor:_backgroundShadowView];
//        [self addSubview:_backgroundShadowView];
        
        _shadowView = [[UIView alloc] initWithFrame:self.bounds];
        _shadowView.backgroundColor = [UIColor whiteColor];
//        [UIView viewWideForShadowColor:_shadowView];
        [UIView viewShadowColor:_shadowView];
        [self addSubview:_shadowView];
        
        _backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH - 20, 90)];
        _backgroundImageView.layer.cornerRadius = 5;
        _backgroundImageView.layer.masksToBounds = YES;
        _backgroundImageView.userInteractionEnabled = YES;
        [_backgroundImageView setContentMode:(UIViewContentModeScaleAspectFill)];
        [self addSubview:_backgroundImageView];
        
        UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] init];
        [tapRecognizer addTarget:self action:@selector(bigButtonTapped:)];
        [_backgroundImageView addGestureRecognizer:tapRecognizer];
        
        
        
        // 头像
        _iconView = [[UIImageView alloc] initWithFrame:CGRectMake(10 * WIDTH, _backgroundImageView.bottom + 15, 30, 30)];
        _iconView.layer.cornerRadius = 15;
        _iconView.backgroundColor = kRandomColor;
        _iconView.layer.masksToBounds = YES;
        [_iconView setContentMode:(UIViewContentModeScaleAspectFill)];
        [self addSubview:_iconView];
        
        // 主标题
        _tagLabel = [[UILabel alloc] initWithFrame:CGRectMake(50 * WIDTH, _backgroundImageView.bottom + 25, 100 * WIDTH, 14 * HEIGHT)];
        //        titleLable.text = _titleString;
        _tagLabel.textColor = kCustomColor(150, 150, 150, 1);
        _tagLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:_tagLabel];
        
        // 副标题
        _authorLabel = [[UILabel alloc] initWithFrame:CGRectMake(_tagLabel.right, _tagLabel.bottom, 100 * WIDTH, 12 * HEIGHT)];
        //        subtitleLable.text = _titleString;
        _authorLabel.textColor = kCustomColor(40, 40, 50, 1);
        _authorLabel.font = [UIFont boldSystemFontOfSize:10];
        [self addSubview:_authorLabel];
        
        // 访问按钮
        _collectionButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _collectionButton.frame = CGRectMake(280 * WIDTH, 0 * HEIGHT, 75 * WIDTH, 30 * HEIGHT);
        _collectionButton.backgroundColor = kCustomColor(40, 40, 50, 1);
        [_collectionButton setTitle:@"收藏" forState:(UIControlStateNormal)];
        _collectionButton.titleLabel.font = [UIFont systemFontOfSize:16];
        _collectionButton.tintColor = [UIColor whiteColor];
        [_collectionButton addTarget:self action:@selector(tapToCollect) forControlEvents:(UIControlEventTouchUpInside)];
        _collectionButton.layer.cornerRadius = 4;
        [UIView viewShadowColor:_collectionButton];
//        [_collectionButton.layer setMasksToBounds:YES];
        [self addSubview:_collectionButton];
        
        
        
        // 描述
        _describeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_tagLabel.right, _tagLabel.bottom, 100 * WIDTH, 12 * HEIGHT)];
        _describeLabel.textColor = kCustomColor(80, 80, 80, 1);
        _describeLabel.font = [UIFont systemFontOfSize:13];
        [_describeLabel setNumberOfLines:0];
        _describeLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [self addSubview:_describeLabel];
        
        _viewNumImageView = [[UIImageView alloc] init];
        _viewNumImageView.image = [UIImage imageNamed:@"ViewNum"];
        [self addSubview:_viewNumImageView];
        
        _viewNumLabel = [[UILabel alloc] init];
        _viewNumLabel.textColor = kCustomColor(180, 180, 180, 1);
        _viewNumLabel.font = [UIFont boldSystemFontOfSize:11];
        _viewNumLabel.text = @"57";
        [self addSubview:_viewNumLabel];
        
        _goodNumImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_viewNumLabel.right + 5, _viewNumLabel.top, 15, 12)];
        _goodNumImageView.alpha = 0.8;
        _goodNumImageView.image = [UIImage imageNamed:@"tabGoodButton"];
        [self addSubview:_goodNumImageView];
        
        _goodLabel = [[UILabel alloc] initWithFrame:CGRectMake(_goodNumImageView.right + 2, _goodNumImageView.top ,30, 11 )];
        _goodLabel.font = [UIFont boldSystemFontOfSize:11];
        _goodLabel.textColor = kCustomColor(180, 180, 180, 1);
        [self addSubview: _goodLabel];
        
        
        //  评论
        _commentNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, self.bottom - 35 , 100 * WIDTH, 20 * HEIGHT)];
        _commentNumLabel.textColor = kCustomColor(150, 150, 150, 1);
        _commentNumLabel.font = [UIFont boldSystemFontOfSize:13];
        [self addSubview:_commentNumLabel];
        
        
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.bottom - 0.5 * HEIGHT, SCREEN_WIDTH, 0.5)];
        _lineView.backgroundColor = kCustomColor(150, 150, 150, 1);
        _lineView.alpha = 0.5;
                [self addSubview:_lineView];
        
        
    }
    
    return self;
}

- (void)tapToCollect{
    NSLog(@"收藏");
}


- (NSUInteger )supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (void)bigButtonTapped:(id)sender {
    
    // Create image info
    JTSImageInfo *imageInfo = [[JTSImageInfo alloc] init];
    imageInfo.image = _backgroundImageView.image;
    imageInfo.referenceRect = _backgroundImageView.frame;
    imageInfo.referenceView = _backgroundImageView.superview;
    imageInfo.referenceContentMode = _backgroundImageView.contentMode;
    imageInfo.referenceCornerRadius = _backgroundImageView.layer.cornerRadius;
    
    // Setup view controller
    JTSImageViewController *imageViewer = [[JTSImageViewController alloc]
                                           initWithImageInfo:imageInfo
                                           mode:JTSImageViewControllerMode_Image
                                           backgroundStyle:JTSImageViewControllerBackgroundOption_None];
    // Present the view controller.
    [imageViewer showFromViewController:self.viewController transition:JTSImageViewControllerTransition_FromOriginalPosition];
}


@end
